package cc.telecomdigital.tdstock.adapter;

import java.util.List;

import cc.telecomdigital.tdstock.R;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class StockAnalysisListItemAdapter extends BaseAdapter
{
	private LayoutInflater				minflater;
	private List<StockANalysisViewHolder>	list;

	public StockAnalysisListItemAdapter(LayoutInflater inflater,
			List<StockANalysisViewHolder> list)
	{
		super();
		this.minflater = inflater;
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position < this.list.size() ? this.list.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return position < this.list.size() ? this.list.get(position).id : -1l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		StockANalysisViewHolder commHolder = this.list.get(position);
		if (convertView == null)
		{
			convertView = minflater.inflate(
					R.layout.stock_analysis_list_item, null);

			//synchronize with iphone
			convertView.setDrawingCacheBackgroundColor(Color.WHITE);
			if (this.list.get(position).item_value == null
					|| this.list.get(position).item_value.length() < 1
					&& (commHolder.item_name != null && commHolder.item_name
							.length() >= 1))
			{
				((TextView) convertView.findViewById(R.id.item_name))
						.setTextColor(Color.BLUE);
			}
			else
			{
				((TextView) convertView.findViewById(R.id.item_name))
						.setTextColor(Color.BLACK);
				((TextView) convertView.findViewById(R.id.item_value))
						.setTextColor(Color.BLACK);
			}

			//synchronize with iphone
		}
		//			    commHolder = new StockANalysisViewHolder();
		//			    commHolder.itemName = (TextView)convertView.findViewById(R.id.item_name);
		//			    commHolder.itemValue = (TextView)convertView.findViewById(R.id.item_value);

		//			    convertView.setTag(commHolder);
		//		   }else {
		//			   commHolder =  (StockANalysisViewHolder) convertView.getTag();
		//		   }

		((TextView) convertView.findViewById(R.id.item_name))
				.setText(commHolder.item_name);
		((TextView) convertView.findViewById(R.id.item_value))
				.setText(this.list.get(position).item_value);
		return convertView;
	}

}
